////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008 Michiel Helvensteijn                                    //
//                                                                            //
// This file is part of the Mist compiler.                                    //
//                                                                            //
// The Mist compiler is free software: you can redistribute it and/or modify  //
// it under the terms of the GNU General Public License as published by       //
// the Free Software Foundation, either version 3 of the License, or          //
// (at your option) any later version.                                        //
//                                                                            //
// The Mist compiler is distributed in the hope that it will be useful,       //
// but WITHOUT ANY WARRANTY; without even the implied warranty of             //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              //
// GNU General Public License for more details.                               //
//                                                                            //
// You should have received a copy of the GNU General Public License          //
// along with the Mist compiler.  If not, see <http://www.gnu.org/licenses/>. //
////////////////////////////////////////////////////////////////////////////////

#ifndef COMPARISONCHAIN_HPP
#define COMPARISONCHAIN_HPP

/******************************************************************************
 * Includes                                                                   *
 ******************************************************************************/

#include <vector>
using std::vector;

#include <string>
using std::string;

#include <boost/shared_ptr.hpp>
using boost::shared_ptr;

#include <boost/enable_shared_from_this.hpp>
using boost::enable_shared_from_this;

#include "ast/expression.hpp"
#include "visitors/visitor.hpp"

/******************************************************************************
 * Extra Types                                                                *
 ******************************************************************************/

enum ComparisonOperator {
	EqualOperator       = 1, // a =    b
	LessThanOperator       , // a <    b
	GreaterThanOperator    , // a >    b
	LessEqualOperator      , // a <=   b
	GreaterEqualOperator   , // a >=   b
	UnequalOperator        , // a <>   b
	ComparableOperator     , // a <>=  b
	NotEqualOperator       , // a !=   b
	NotLessOperator        , // a !<   b
	NotGreaterOperator     , // a !>   b
	NotLessEqualOperator   , // a !<=  b
	NotGreaterEqualOperator, // a !>=  b
	NotUnequalOperator     , // a !<>  b
	NotComparableOperator  , // a !<>= b
	IdentityOperator       , // a ==   b
	NotIdentityOperator      // a !==  b
};

string to_string(ComparisonOperator comparison_operator);

struct Comparison {
	shared_ptr<Expression> left_operand;
	ComparisonOperator comparison_operator;
	shared_ptr<Expression> right_operand;
};

/******************************************************************************
 * ComparisonChain Class                                                      *
 ******************************************************************************/

class ComparisonChain : public Expression, public enable_shared_from_this<ComparisonChain> {
	
	ACCEPT_VISITOR
	
	public:
		
		static shared_ptr<ComparisonChain> create(shared_ptr<Expression> operand1, ComparisonOperator operator1, shared_ptr<Expression> operand2);
		
		ComparisonChain(shared_ptr<Expression> operand1, ComparisonOperator operator1, shared_ptr<Expression> operand2);
		
		bool equals(shared_ptr<Node> other);
		
		DEFINE_POINTER_LIST(Expression, operand, s)
		
		DEFINE_VALUE_LIST(ComparisonOperator, comparison_operator, s)
		
		const vector<Comparison> comparisons() const;
};

#endif // COMPARISONCHAIN_HPP
